package org.lalib.controller.service;

import java.util.List;

import org.lalib.acquire.IControllerService;
import org.lalib.entity.object.EUser;
import org.lalib.entity.object.EUserGroup;
import org.lalib.mediator.MCategory;
import org.lalib.mediator.MUser;
import org.lalib.mediator.MUserGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "cUserService")
public class CUserService implements IControllerService {

	private static final long serialVersionUID = 1L;

	@Autowired
	MCategory mCategory;

	@Autowired
	private MUserGroup mUserGroup;

	@Autowired
	private MUser mUser;

	public void save(EUser user, Long selectedUserGroupId) {
		EUserGroup selectedUserGroup = mUserGroup.getEntityById(selectedUserGroupId);
		user.setUserGroup(selectedUserGroup);
		mUser.insert(user);
	}

	public void update(EUser user) {
		mUser.update(user);
	}

	public void delete(EUser user) {
		mUser.remove(user);
	}

	public EUser getUserById(Long id) {
		return mUser.getEntityById(id);
	}

	public List<EUser> getUserListForGivenName(String name) {
		return mUser.getUserListForGivenName(name);
	}

	public List<EUser> getAllUsers() {
		return mUser.getAllUsers();
	}

}